package com.youka.bussiness.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youka.bussiness.common.utils.BaseUtil;
import com.youka.bussiness.dao.entity.CouponRedemption;
import com.youka.bussiness.service.CouponRedemptionService;
import com.youka.bussiness.service.req.CouponRedemptionReqDto;
import com.youka.bussiness.service.req.CouponRedemptionUpdateDto;
import com.youka.bussiness.service.req.CouponRedemptionPageDto;
import com.youka.bussiness.service.res.CouponRedemptionDto;;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youka.bussiness.common.bean.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import com.youka.bussiness.dao.CouponRedemptionMapper;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 电子券核销记录表 Service 实现类
 *
 * @author lfc
 * @date 2024-06-30 16:47:28
 */
@Service
public class CouponRedemptionServiceImpl extends ServiceImpl<CouponRedemptionMapper, CouponRedemption> implements CouponRedemptionService {

    @Resource
    private CouponRedemptionMapper couponRedemptionMapper;

    /**
     * 查询详情
     *
     * @param id 查询参数
     * @return couponRedemptionDto
     */
    @Override
    public CouponRedemptionDto selectById(long id) {
        CouponRedemptionDto couponRedemptionDto = new CouponRedemptionDto();
        CouponRedemption couponRedemption = couponRedemptionMapper.selectById(id);
        if (couponRedemption != null){
            BeanUtils.copyProperties(couponRedemption,couponRedemptionDto);
        }
        return couponRedemptionDto;
    }

    /**
     * 集合查询电子券核销记录表
     *
     * @param dto 查询参数
     * @return Page
     */
    @Override
    public List<CouponRedemptionDto> selectByList(CouponRedemptionReqDto dto) {
        LambdaQueryWrapper<CouponRedemption> wrapper = new LambdaQueryWrapper();
        List<CouponRedemption> CouponRedemptions = couponRedemptionMapper.selectList(wrapper);
        return BaseUtil.listToList(CouponRedemptions, CouponRedemptionDto.class);
    }

    /**
     * 分页查询电子券核销记录表
     *
     * @param dto 查询参数
     * @return Page
     */
    @Override
    public IPage selectByPage(CouponRedemptionPageDto dto) {
        QueryWrapper<CouponRedemption> wrapper = Page.getPageWrapper(dto);
        return Page.copyProperties(this.page(Page.defaultPage(dto.getPageIndex(), dto.getPageSize()), wrapper)
                ,CouponRedemptionDto.class);
    }

    /**
     * 新增电子券核销记录表
     *
     * @param dto 电子券核销记录表
     * @return 新增结果
     */
    @Override
    public void insert(CouponRedemptionReqDto dto) {
        CouponRedemption couponRedemption = new CouponRedemption();
        BeanUtils.copyProperties(dto,couponRedemption);
        couponRedemptionMapper.insert(couponRedemption);
    }

    /**
       * 统计
        * @param dto
       * @return
       */
    @Override
     public  CouponRedemptionDto selectCount(CouponRedemptionReqDto dto){
        CouponRedemptionDto resp = new CouponRedemptionDto();
        couponRedemptionMapper.selectCount(new LambdaQueryWrapper<CouponRedemption>());
        return resp;
    }

    /**
     * 更新电子券核销记录表
     * (根据主键)
     *
     * @param dto 电子券核销记录表
     * @return 更新结果
     */
    @Override
    public void update(CouponRedemptionUpdateDto dto) {
        CouponRedemption couponRedemption =new CouponRedemption();
        BeanUtils.copyProperties(dto,couponRedemption);
        couponRedemptionMapper.updateById(couponRedemption);
    }

    /**
     * 删除电子券核销记录表
     * (根据主键)
     *
     * @param redemptionId redemptionId
     * @return 删除结果
     */
    @Override
    public void deleteById(Integer redemptionId) {
        couponRedemptionMapper.deleteById(redemptionId);
    }


}
